/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entidade;

import controlo.util.Conexao;
import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.model.SelectItem;

/**
 *
 * @author Lomanda
 */

public class ContaDAO
{
    Connection conn;
    List<SelectItem> listaContas = new LinkedList<SelectItem>();

    public ContaDAO()
    {     
        try
        {
            conn = Conexao.getConnection();
        } catch (Exception ex) {
            Logger.getLogger(ContaDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public List<SelectItem> contasDependentes(int idMoeda,int idTipoConta) throws Exception
    {
         LinkedList<SelectItem> listaConta = new LinkedList<SelectItem>();
        
         try
         {
            conn = Conexao.getConnection();
            Statement stm = conn.createStatement();
            
            listaConta.add(new SelectItem(null,"---"));
           // listaConta.get(0).setDisabled(true);
            //listaConta.get(0).setNoSelectionOption(true);
            
            
            ResultSet res = stm.executeQuery("SELECT c.nomeConta,c.idConta "
                    + " FROM conta as c,conta_moeda as cm"
                    + " WHERE c.idConta=cm.idConta"
                    + " AND cm.idMoeda="+ idMoeda
                    + " AND c.idTipoConta="+ idTipoConta);

            while(res.next())
            {
     
                listaConta.add(new SelectItem(res.getInt("idConta"),res.getString("nomeConta")));
            }

            res.close();
            stm.close();
         }
         catch(Exception e)
         {
             e.printStackTrace();
         }

         return listaConta;
    }
}